package msearch.logic;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import msearch.db.DBManager;
import msearch.model.Mp3Object;

public class Search {

	public static List<Mp3Object> searchByName(String name){
		DBManager dbm = new DBManager();
		List<Mp3Object> mp3s = new ArrayList<Mp3Object>();
		ResultSet result= dbm.search("select * from mp3 where name like '%"+name+"%'");
		try {
			while(result.next()){
				Mp3Object mo = new Mp3Object();
				mo.setArtist(result.getString("artist"));
				mo.setFilePath(result.getString("filepath"));
				mo.setName(result.getString("name"));
				mo.setPublishDate(result.getString("publishdate"));
				mp3s.add(mo);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return mp3s;
	}
}
